package demo.selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;

/**
 * @Author: Qiao Hang
 * @CreateDate: 2021/11/2 上午10:52
 * @UpdateDate:
 * @Description:
 */
public class TestMain {


    public static void main(String[] args) {
        // 浏览器驱动.
        System.setProperty("webdriver.chrome.driver", "/Users/icasue/Desktop/lbs-server-plugins/icasue-plugins-demos/icasue-demo-selenium/src/main/resources/drivers/chromedriver_98");
        // 创建浏览器驱动
        ChromeDriver driver = null;
        try {
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);

            driver = new ChromeDriver(chromeOptions);
            // 打开网站 www.ssense.com/zh-cn
            driver.get("https://www.ssense.com/zh-cn");
            //等待10秒
            //new WebDriverWait(driver, Duration.ofSeconds(10));

            // 点击主页登录连接.
            driver.findElement(By.id("login-link")).click();

            // 获取机器人验证点击图片, 并长摁.
            WebElement img = driver.findElement(By.tagName("img"));
            new Actions(driver).clickAndHold(img).perform();

            // 浏览器刷新.
            driver.navigate().refresh();
            String title = driver.getTitle();
            System.out.println("当前页面标题:" + title);


        }catch (Throwable e){
            e.printStackTrace();
        }finally {
            if(driver != null){
                // 退出驱动，退出驱动进程，远程驱动进程,
                // 关闭当前驱动打开的所有tab或者window， 关闭浏览器，清理session.
                driver.quit();
            }
        }
    }
}
